//
//  EditCell.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 16/1/19.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "EditCell.h"
#import "Masonry.h"
#import "UIColor+CL.h"

@implementation EditCell


-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if(self){
        
        UIView *v = [self createUI];
        // UIView要加入到self.contentView上 不要加入到self
        [self.contentView addSubview:v];
        UIView *superview = self.contentView;
        UIEdgeInsets edge = UIEdgeInsetsMake(0, 0, 0, 0);
        [v mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(superview).insets(edge);
        }];
        
    }
    return self;
}


-(void)setEditIs:(BOOL)isEdit{
    if(isEdit){
        _titleText.enabled = YES;
        _titleText.hidden = NO;
        _titleLabel.hidden = YES;
        
    }
    else{
        _titleText.enabled = NO;
        _titleText.hidden = YES;
        _titleLabel.hidden = NO;
    }
    
}

-(UIView *)createUI{
    UIView *baseView = [[UIView alloc]init];
    
    UIView *v= [[UIView alloc]init];
    [baseView addSubview:v];
    v.userInteractionEnabled= YES;
    _title = [[UILabel alloc]init];
    [v addSubview:_title];
    [_title sizeToFit];
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(24/2);
        make.centerY.equalTo(v.mas_centerY);
        make.width.equalTo(@(70));
        //        make.height.equalTo(@(30));
    }];
    _title.text = @"未知";
    _title.textColor =[UIColor colorWithHex:0x5c5c5c];
    
    _titleText = [[CustomLabel alloc]init];
    _titleText.numberOfLines = 0;
    _titleText.lineBreakMode = NSLineBreakByTruncatingHead;
    
    [v addSubview:_titleText];
    [_titleText sizeToFit];
    [_titleText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_title.mas_right).offset(38/2);
        make.centerY.equalTo(v.mas_centerY);
        make.height.equalTo(@(30));
        make.right.equalTo(v.mas_right).offset(-30/2);
    }];
    _titleText.textColor = [UIColor colorWithHex:0x696969];
    _titleText.font = [UIFont systemFontOfSize:16];
    
    
    _titleLabel = [[UILabel alloc]init];
    [v addSubview:_titleLabel];
    [_titleLabel sizeToFit];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_title.mas_right).offset(38/2);
        make.centerY.equalTo(v.mas_centerY);
        make.right.equalTo(v.mas_right).offset(-30/2);
    }];
    _titleLabel.numberOfLines = 0;
    _titleLabel.hidden = YES;
    _titleLabel.font = [UIFont systemFontOfSize:16];
    _titleLabel.textColor = [UIColor colorWithHex:0x696969];
    
    _title.numberOfLines = 0;
    UIImageView *line =[[UIImageView alloc]init];
    [v addSubview:line];
    line.backgroundColor = [UIColor colorWithHex:0xd1d1d1];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left);
        make.right.equalTo(v.mas_right);
        make.bottom.equalTo(v.mas_bottom);
        make.height.equalTo(@(1));
    }];
    
    _title.textColor = [UIColor colorWithRed:0xa3/255.0 green:0xa3/255.0 blue:0xa3/255.0 alpha:1];
    _title.font = [UIFont systemFontOfSize:28/2];
    
    _titleLabel.textColor = [UIColor colorWithRed:0x5b/255.0 green:0x5b/255.0 blue:0x5b/255.0 alpha:1];
    _titleLabel.font = [UIFont systemFontOfSize:32/2];

    return v;
}

@end
